# Copyright (C) 2011 Texas Insruments, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

POOL_MAX_SIZE ?= 0

SOSAL_ROOT ?= $(HOST_ROOT)
SOSAL_INC := $(SOSAL_ROOT)/include

SYSIDIRS := $(SOSAL_INC)
SYSLDIRS :=
SYSDEFS  :=

ifeq ($(TARGET_PLATFORM),PC)
    ifeq ($(TARGET_OS),LINUX)
        INSTALL_LIB ?= /usr/lib
        INSTALL_BIN ?= /usr/bin
        INSTALL_INC ?= /usr/include
        SYSIDIRS += /usr/include
        SYSLDIRS += /usr/lib
        SYSDEFS += SCREEN_DIM_X=1024 SCREEN_DIM_Y=768
        SYSDEFS += _XOPEN_SOURCE=700 _BSD_SOURCE=1 _GNU_SOURCE=1
        SYSDEFS += SOSAL_USE_SHARED_T SOSAL_USE_FS SOSAL_USE_XML
        UVC_INC := /usr/include
        ifneq ($(filter `cat /proc/version`,Ubuntu),)
            GTK_PKG := gtk+-2.0
            EXPLAIN_PKG := libexplain
            XML_PKG := libxml-2.0
        endif
        # should be "gtk+-2.0" on Ubuntu
        ifneq ($(GTK_PKG),)
            GTK_INC := $(subst -I,,$(shell pkg-config --cflags-only-I $(GTK_PKG)))
            GTK_LDIRS := $(shell pkg-config --variable=libdir $(GTK_PKG))
            GTK_LIBS := $(subst -l,,$(shell pkg-config --libs-only-l $(GTK_PKG)))
            SYSDEFS+=SOSAL_USE_GTK GTK_SUPPORT
        endif
        # should be "libexplain" on Ubuntu
        ifneq ($(EXPLAIN_PKG),)
            EXPLAIN_LIBS := $(subst -l,,$(shell pkg-config --libs-only-l $(EXPLAIN_PKG)))
            SYSDEFS += SOSAL_USE_EXPLAIN
        endif
        # should be "libxml-2.0" on Ubuntu
        ifneq ($(XML2_PKG),)
            XML2_LIBS := $(subst -l,,$(shell pkg-config --libs-only-l $(XML2_PKG)))
            XML2_INCS := $(subst -I,,$(shell pkg-config --cflags $(XML2_PKG)))
            SYSDEFS += SOSAL_USE_XML
        endif
    else ifeq ($(TARGET_OS),DARWIN)
        INSTALL_LIB ?= /opt/local/lib
        INSTALL_BIN ?= /opt/local/bin
        INSTALL_INC ?= /opt/local/include
        SYSDEFS += SCREEN_DIM_X=1024 SCREEN_DIM_Y=768
        SYSDEFS += _XOPEN_SOURCE=700 _BSD_SOURCE=1 _GNU_SOURCE=1
        SYSDEFS += SOSAL_USE_FS SOSAL_USE_SHARED_T
    else ifeq ($(TARGET_OS),CYGWIN)
        INSTALL_LIB ?= /usr/lib
        INSTALL_BIN ?= /usr/bin
        INSTALL_INC ?= /usr/include
        SYSDEFS += SCREEN_DIM_X=1024 SCREEN_DIM_Y=768
        SYSDEFS += _XOPEN_SOURCE=700 _BSD_SOURCE=1 _GNU_SOURCE=1 WINVER=0x501
        SYSDEFS += SOSAL_USE_FS SOSAL_USE_SHARED_T
    else ifeq ($(TARGET_OS),Windows_NT)
        INSTALL_LIB ?= "${windir}\\system32"
        INSTALL_BIN ?= "${windir}\\system32"
        #INSTALL_INC ?=
        POOL_MAX_SIZE := 1024
        SYSIDIRS+=$(SOSAL_INC)/windows
        SYSDEFS += WIN32_LEAN_AND_MEAN WIN32
        SYSDEFS += _WIN32 _CRT_SECURE_NO_DEPRECATE WINVER=0x0501 _WIN32_WINNT=0x0501
        SYSDEFS += SOSAL_USE_SHARED_T SOSAL_USE_FS
        SYSDEFS += SCREEN_DIM_X=1024 SCREEN_DIM_Y=768
    endif
else
    ifeq ($(TARGET_PLATFORM),DEVBOARD)
        # Self-hosting embedded targets like ARM development boards
        INSTALL_LIB ?= /usr/lib
        INSTALL_BIN ?= /usr/bin
        INSTALL_INC ?= /usr/include
        SYSDEFS += SCREEN_DIM_X=1920 SCREEN_DIM_Y=1080 # Assume 1080p
        SYSDEFS += _XOPEN_SOURCE=700 _BSD_SOURCE=1 _GNU_SOURCE=1
        SYSDEFS += SOSAL_USE_SHARED_T SOSAL_USE_FS
        ifeq ($(USE_BO),true)
            SYSDEFS += SOSAL_USE_BO
            ifneq ($(findstring SOSAL_USE_BO, $(SYSDEFS)),)
                # remove the -I and -l switches which assume GCC
                MEM_INCS += $(subst -I,,$(shell pkg-config --cflags libdrm libdrm_omap))
                MEM_LIBS += $(subst -l,,$(shell pkg-config --libs libdrm libdrm_omap))
            endif
        endif
        UVC_INC := /usr/include
        ifneq ($(GTK_PKG),)
            GTK_INC := $(subst -I,,$(shell pkg-config --cflags-only-I $(GTK_PKG)))
            GTK_LDIRS := $(shell pkg-config --variable=libdir $(GTK_PKG))
            GTK_LIBS := $(subst -l,,$(shell pkg-config --libs-only-l $(GTK_PKG)))
            SYSDEFS+=SOSAL_USE_GTK GTK_SUPPORT
        endif
        TARGET_NUM_CORES := $(HOST_NUM_CORES)
        TARGET_OS := LINUX
        TARGET_CPU := $(HOST_CPU)
    endif
endif

ifdef SOSAL_DEBUG
SYSDEFS+=SOSAL_DEBUG=$(SOSAL_DEBUG)
ifdef SOSAL_ZONE_MASK
SYSDEFS+=SOSAL_ZONE_MASK=$(SOSAL_ZONE_MASK)
endif
endif

